#region License

/*
  GShield - Game Shield
  Copyright (C) 2006-2007 WaveTech Digital Technologies, Inc.
                                http://www.wtdt.com

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#endregion License

#region Includes

using System;
using ExceptionManager;
using WaveTech.GShield.Common;
using WaveTech.GShield.Data;

#endregion

namespace PassRecovery
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			UnhandledExceptionManager.AddHandler(true);
			Setting s = SettingsDAO.Get();

			Console.WriteLine("#############################################################");
			Console.WriteLine("#                                                           #");
			Console.WriteLine("#                GShield Password Recovery                  #");
			Console.WriteLine("#                                                           #");
			Console.WriteLine("#############################################################");

			Console.WriteLine("");
			Console.WriteLine("Please answer the following questions to reset your password.");
			Console.WriteLine("");
			Console.WriteLine("Question 1:");
			Console.WriteLine(LpqDAO.GetQuestionById(s.LPQ1Id));
			Console.Write("Answer: ");

			string answer1 = Console.ReadLine();

			if (answer1.Trim() == s.LPQ1Ans.Trim())
			{
				Console.WriteLine("");
				Console.WriteLine("Question 2:");
				Console.WriteLine(LpqDAO.GetQuestionById(s.LPQ2Id));
				Console.Write("Answer: ");

				string answer2 = Console.ReadLine();

				if (answer2.Trim() == s.LPQ2Ans.Trim())
				{
					Console.WriteLine("");
					Console.WriteLine("Please type in your new password:");

					string reset1 = Console.ReadLine();
					Console.WriteLine("");
					Console.WriteLine("Please retype in your new password:");

					string reset2 = Console.ReadLine();
					Console.WriteLine("");

					if (reset1.Trim() == reset2.Trim())
					{
						s.AdminPassword = Hash.ComputeHash(reset2.Trim(), "SHA256", null);

						SettingsDAO.Update(s);

						Console.WriteLine("");
						Console.WriteLine("Your Password has been reset, Press Enter to Exit.");
						Console.ReadLine();
					}
					else
					{
						Console.WriteLine("Your Passwords do not match!");
					}
				}
				else
				{
					Console.WriteLine("Answer for Question 2 is incorrect.");
					Environment.Exit(1);
				}
			}
			else
			{
				Console.WriteLine("Answer for Question 1 is incorrect.");
				Environment.Exit(1);
			}
		}
	}
}